package com.cn.bukeManage.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.bukeManage.pojo.Message;
import com.cn.bukeManage.service.MessageService;

//这是消息管理
@Controller
@RequestMapping("/message")
public class MessageController {
	@Resource
	private MessageService messageService;
	//顾客消息
	@RequestMapping("/customerMessage")
	public String customerMessage(Model model ,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,0);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","customerMessage");
		model.addAttribute("messages", messages);
		return "message/customerMessage";
	}
	//顾客消息搜索
	@RequestMapping("/screahCustomerMessage")
	public String screahCustomerMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,0,screah);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","customerMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchCustomerMessage";
	}
	//增加消息
	@RequestMapping("/addMessage")
	@ResponseBody
	public Integer addcustomerMessage(Message message){
		Integer date = messageService.addcustomerMessage(message);
		return date;
	}
	//删除消息
	@RequestMapping("/toDeleteMessage")
	@ResponseBody
	public Integer toDeleteMessage(Integer messageId){
		Integer date = messageService.deleteMessage(messageId);
		return date;
	}
	//修改消息
	@RequestMapping("/toUpdateMessage")
	@ResponseBody
	public Message toUpdateMessage(Integer messageId){
		Message message= messageService.toUpdateMessage(messageId);
		return message;
	}
	//保存修改
	@RequestMapping("/updateMessage")
	@ResponseBody
	public Integer updateMessage(Message message){
		Integer date = messageService.updateMessage(message);
		return date;
	}
	//工人消息
	@RequestMapping("/workerMessage")
	public String workerMessage(Model model,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,1);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","workerMessage");
		model.addAttribute("messages", messages);
		return "message/workerMessage";
	}
	//工人消息搜索
	@RequestMapping("/screahWorkerMessage")
	public String screahWorkerMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,1,screah);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","workerMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchWorkerMessage";
	}
	//经销商消息
	@RequestMapping("/dealerMessage")
	public String dealerMessage(Model model,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,2);
		List<Message> messages2=messageService.getMessageByType(model,currentPage,4);
		List<Message> messages3=messageService.getMessageByType(model,currentPage,7);
		for(Message message:messages2){
			messages.add(message);
		}
		for(Message message:messages3){
			messages.add(message);
		}
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","dealerMessage");
		model.addAttribute("messages", messages);
		return "message/dealerMessage";
	}
	//经销商消息搜索
	@RequestMapping("/screahDealerMessage")
	public String screahDealerMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,2,screah);
		List<Message> messages2=messageService.screahMessageByType(model,currentPage,4,screah);
		List<Message> messages3=messageService.screahMessageByType(model,currentPage,7,screah);
		for(Message message:messages2){
			messages.add(message);
		}
		for(Message message:messages3){
			messages.add(message);
		}
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","dealerMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchDealerMessage";
	}
	//供货商消息
	@RequestMapping("/supplierMessage")
	public String supplierMessage(Model model,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,6);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","supplierMessage");
		model.addAttribute("messages", messages);
		return "message/supplierMessage";
	}
	//供货商消息搜索
	@RequestMapping("/screahSupplierMessage")
	public String screahSupplierMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,6,screah);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","supplierMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchSupplierMessage";
	}
	//商家消息
	@RequestMapping("/businessMessage")
	public String businessMessage(Model model,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,5);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","businessMessage");
		model.addAttribute("messages", messages);
		return "message/businessMessage";
	}
	//商家消息搜索
	@RequestMapping("/screahBusinessMessage")
	public String screahBusinessMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,5,screah);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","businessMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchBusinessMessage";
	}
	//工厂消息
	@RequestMapping("/factoryMessage")
	public String factoryMessage(Model model,Integer currentPage){
		List<Message> messages=messageService.getMessageByType(model,currentPage,3);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","factoryMessage");
		model.addAttribute("messages", messages);               
		return "message/factoryMessage";
	}
	//工厂消息搜索
	@RequestMapping("/screahFactoryMessage")
	public String screahFactoryMessage(Model model,String screah,Integer currentPage){
		List<Message> messages=messageService.screahMessageByType(model,currentPage,3,screah);
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","factoryMessage");
		model.addAttribute("messages", messages);
		model.addAttribute("screah",screah.trim());
		return "message/searchFactoryMessage";
	}
	//发送消息设置
	@RequestMapping("/sendMessage")
	public String sendMessage(Model model,Integer currentPage){
		model.addAttribute("oneMenu","message");
		model.addAttribute("twoMenu","sendMessage");
		return "message/sendMessage";
	}
}
